Last updated: 2024-04-23

Checks: 7 0

Knit directory: RA_SingleCellAnalysis/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20240328) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 6ac7e20. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/figure/
    Ignored:    data/cellbender_data_h5/
    Ignored:    output/._Cluster_Marker_Genes.xlsx
    Ignored:    output/00_sce_DataPreparation.rds
    Ignored:    output/01_sce_Preprocessing.rds
    Ignored:    output/02_sce_DimensionalityReduction.rds
    Ignored:    output/03_sce_Integration_Batchelor.rds
    Ignored:    output/03_sce_Integration_Harmony.rds
    Ignored:    output/04_sce_Clustering.rds
    Ignored:    output/05_sce_CelltypeAnnotation.rds
    Ignored:    output/05_sce_CelltypeAnnotation.rdss
    Ignored:    output/Cluster_Marker_Genes.xlsx

Unstaged changes:
    Modified:   analysis/01_Preprocessing.Rmd
    Modified:   analysis/02_DimensionalityReduction.Rmd
    Modified:   analysis/03_Integration_Batchelor.Rmd
    Modified:   analysis/03_Integration_Harmony.Rmd
    Modified:   analysis/05_CelltypeAnnotation.Rmd
    Modified:   code/standard_libraries.R
    Modified:   data/metadata/Metadata_Master.csv

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/00_DataPreparation.Rmd) and HTML (docs/00_DataPreparation.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 6ac7e20 sarloet 2024-04-23 Fix
Rmd f73b2cd sarloet 2024-04-19 fix
html b1fc000 sarloet 2024-04-19 Build site.
Rmd 3f5d694 sarloet 2024-04-19 Rerun
Rmd c889cbe sarloet 2024-04-11 fix
Rmd 530ec4b sarloet 2024-04-05 fix
Rmd 64ae186 sarloet 2024-04-05 fix
html 5067fa6 sarloet 2024-04-04 Build site.
html fa0211e sarloet 2024-04-04 Build site.
Rmd d41ba14 sarloet 2024-04-03 fix
html bc77174 sarloet 2024-04-03 Build site.
Rmd 8543968 sarloet 2024-04-03 fix
Rmd 960ebd0 sarloet 2024-04-03 fix
Rmd eb121be sarloet 2024-04-03 fix
html ef4c495 sarloet 2024-04-02 Build site.
Rmd 9e3e00a sarloet 2024-04-02 commit changes
Rmd d291fd3 sarloet 2024-04-02 initial commit
html d291fd3 sarloet 2024-04-02 initial commit

Data Preparation and Overview

Setup

Standard packages

library(here)
source(here("code", "standard_libraries.R"))

Additional Packages

suppressPackageStartupMessages({
library(DropletUtils)
})

Set parameter

set.seed(100)
bpp <- BiocParallel::MulticoreParam(parallel::detectCores()-1, RNGseed=100)
path <- here::here()

Load Data

Load Cellbender output matrices

Load in the filtered feature barcode matrices from Cellbender of each sample and save them as sce object.

#Load Dataset
rawdata_folder <- paste0(path,"/data/cellbender_data_h5/")

#Get file names
filenames <- list.files(rawdata_folder ,recursive = F, full.names = F,pattern = "\\_filtered.h5$")
filepaths <- paste(rawdata_folder,filenames,sep = "")

#Load data as sce object
sce<-read10xCounts(samples = filepaths, sample.names = filenames,col.names=T,type="HDF5")

#Edit Filenames 
colData(sce)$Sample = sub("\\_w_introns.*", "", sub("cellbender_output_", "", as.character(colData(sce)$Sample)))


sce
class: SingleCellExperiment 
dim: 36601 119652 
metadata(1): Samples
assays(1): counts
rownames(36601): ENSG00000243485 ENSG00000237613 ... ENSG00000278817
  ENSG00000277196
rowData names(3): ID Symbol Type
colnames(119652): 1_AAGTACCGTCTCTCAC-1 1_GACTCTCAGGTAACTA-1 ...
  17_AGGTGTTGTGGCATCC-1 17_GCCAGCACACAAGTGG-1
colData names(2): Sample Barcode
reducedDimNames(0):
mainExpName: NULL
altExpNames(0):

Load and add Metadata

#Metadata path
metadata_folder <- paste0(path,"/data/metadata/Metadata_Master.csv")

#Load metadata
metadata_df <-read.csv(metadata_folder, header=TRUE, sep=",")
metadata_df
#Add metadata to sce
colData(sce) <- dplyr::left_join(as.data.frame(colData(sce)),
                                   metadata_df, 
                                   by= c("Sample" = "Sample"),
                                   suffix=c(".x",".y")) %>% 
      #dplyr::select(Sample, Barcode, Diagnosis, sex, Age, Joint.Location, protocol, Pathotype,Krenn total score,) %>% 
      dplyr::select(-one_of("Comments")) %>% #select all except
      DataFrame(row.names=colnames(sce))

#Set Sample names
names(colData(sce))[which(names(colData(sce))=="Sample")]="Orig.Identifier"
names(colData(sce))[which(names(colData(sce))=="ID")]="Sample"

#make row and col names unique
colnames(sce) <- paste0(sce$Sample, ".", sce$Barcode)
rownames(sce) <- paste0(rowData(sce)$ID, ".", rowData(sce)$Symbol)

Exclude Samples

#Dimensions of count matrix
dim(sce)
[1]  36601 119652

Explore dataset

Dimensions of the count matrix

#Exclude sample SynBio130 due to low sequencing depth
#sce <- sce[,sce$Sample!="SynBio130"]
#Feautures/row data
data.frame(colData(sce))
#Droplet details / row data
data.frame(rowData(sce))

Exploratory plots

Histogramm with number of cells

Show the number of cells detected in each sample or joint location before filtering

Per Sample

#Histogramm with number of cells per sample
ggplot(colData(sce), aes(x=Sample))+geom_bar()+ coord_flip()+ ggtitle("Number of cells per sample") + theme_bw()

Version Author Date
b1fc000 sarloet 2024-04-19
5067fa6 sarloet 2024-04-04
bc77174 sarloet 2024-04-03
d291fd3 sarloet 2024-04-02
data.frame(as.list(table(colData(sce)$Sample)))

Per Joint Location

#Histogramm with number of cells per sample
ggplot(colData(sce), aes(x=Joint.Location))+geom_bar()+ coord_flip()+ ggtitle("Number of cells per sample") + theme_bw()

Version Author Date
b1fc000 sarloet 2024-04-19
5067fa6 sarloet 2024-04-04
bc77174 sarloet 2024-04-03
data.frame(as.list(table(colData(sce)$Joint.Location)))

Plot number of genes detected per cell

This plot shows cell counts per sample / count occurrence

#Number of genes detected per cell
#Total UMI for a gene versus the number of times detected
genesPerCell <- colSums(counts(sce) > 0)
plot(density(genesPerCell), xlab="Genes per cell", main="Number of genes detected per cell")

Version Author Date
b1fc000 sarloet 2024-04-19
5067fa6 sarloet 2024-04-04
bc77174 sarloet 2024-04-03
d291fd3 sarloet 2024-04-02

Plot transcript capture efficiency

This plot gives an idea about the sequencing depth and if the sequencing has reached saturation or not. Plotted is the total gene count across all cells (x-axis) vs Proportion of cells the gene is detected in (y-axis) where each dot represents a gene.

#transcript_capture_efficiency
#Total UMI for a gene versus the number of times detected
tmpCounts <- counts(sce)

plot(rowSums(tmpCounts),
     rowMeans(tmpCounts > 0),
     log = "x",
     xlab="total number of UMIs",
     ylab="proportion of cells expressing the gene",
     main="Total UMI for a gene vs times detected")

Version Author Date
b1fc000 sarloet 2024-04-19
5067fa6 sarloet 2024-04-04
bc77174 sarloet 2024-04-03
d291fd3 sarloet 2024-04-02

Save the dataset

saveRDS(sce, file =paste0(path,'/output/00_sce_DataPreparation.rds'))

sessionInfo()
R version 4.3.3 (2024-02-29)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.4.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Warsaw
tzcode source: internal

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] DropletUtils_1.22.0         gridExtra_2.3              
 [3] scran_1.30.2                scater_1.30.1              
 [5] scuttle_1.12.0              SingleCellExperiment_1.24.0
 [7] SummarizedExperiment_1.32.0 Biobase_2.62.0             
 [9] GenomicRanges_1.54.1        GenomeInfoDb_1.38.8        
[11] IRanges_2.36.0              S4Vectors_0.40.2           
[13] BiocGenerics_0.48.1         MatrixGenerics_1.14.0      
[15] matrixStats_1.3.0           dplyr_1.1.4                
[17] ggplot2_3.5.0               BiocParallel_1.36.0        
[19] here_1.0.1                  workflowr_1.7.1            

loaded via a namespace (and not attached):
 [1] bitops_1.0-7              rlang_1.1.3              
 [3] magrittr_2.0.3            git2r_0.33.0             
 [5] compiler_4.3.3            getPass_0.2-4            
 [7] DelayedMatrixStats_1.24.0 callr_3.7.6              
 [9] vctrs_0.6.5               stringr_1.5.1            
[11] pkgconfig_2.0.3           crayon_1.5.2             
[13] fastmap_1.1.1             XVector_0.42.0           
[15] labeling_0.4.3            utf8_1.2.4               
[17] promises_1.3.0            rmarkdown_2.26           
[19] ps_1.7.6                  ggbeeswarm_0.7.2         
[21] xfun_0.43                 bluster_1.12.0           
[23] zlibbioc_1.48.2           cachem_1.0.8             
[25] beachmat_2.18.1           jsonlite_1.8.8           
[27] highr_0.10                later_1.3.2              
[29] rhdf5filters_1.14.1       DelayedArray_0.28.0      
[31] Rhdf5lib_1.24.2           irlba_2.3.5.1            
[33] parallel_4.3.3            cluster_2.1.6            
[35] R6_2.5.1                  bslib_0.7.0              
[37] stringi_1.8.3             limma_3.58.1             
[39] jquerylib_0.1.4           Rcpp_1.0.12              
[41] knitr_1.45                R.utils_2.12.3           
[43] httpuv_1.6.15             Matrix_1.6-5             
[45] igraph_2.0.3              tidyselect_1.2.1         
[47] rstudioapi_0.16.0         abind_1.4-5              
[49] yaml_2.3.8                viridis_0.6.5            
[51] codetools_0.2-19          processx_3.8.4           
[53] lattice_0.22-5            tibble_3.2.1             
[55] withr_3.0.0               evaluate_0.23            
[57] pillar_1.9.0              whisker_0.4.1            
[59] generics_0.1.3            rprojroot_2.0.4          
[61] RCurl_1.98-1.14           sparseMatrixStats_1.14.0 
[63] munsell_0.5.1             scales_1.3.0             
[65] glue_1.7.0                metapod_1.10.1           
[67] tools_4.3.3               BiocNeighbors_1.20.2     
[69] ScaledMatrix_1.10.0       locfit_1.5-9.9           
[71] fs_1.6.3                  rhdf5_2.46.1             
[73] grid_4.3.3                edgeR_4.0.16             
[75] colorspace_2.1-0          GenomeInfoDbData_1.2.11  
[77] HDF5Array_1.30.1          beeswarm_0.4.0           
[79] BiocSingular_1.18.0       vipor_0.4.7              
[81] cli_3.6.2                 rsvd_1.0.5               
[83] fansi_1.0.6               S4Arrays_1.2.1           
[85] viridisLite_0.4.2         gtable_0.3.4             
[87] R.methodsS3_1.8.2         sass_0.4.9               
[89] digest_0.6.35             SparseArray_1.2.4        
[91] ggrepel_0.9.5             dqrng_0.3.2              
[93] farver_2.1.1              R.oo_1.26.0              
[95] htmltools_0.5.8.1         lifecycle_1.0.4          
[97] httr_1.4.7                statmod_1.5.0